package org.ibase4j.thired;

import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.ibase4j.system.model.SysMenu;
import org.ibase4j.system.service.SysMenuService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import top.ibase4j.core.base.BaseController;

import java.util.Map;

/**
 * 菜单管理
 * 
 * @author ShenHuaJie
 * @version 2016年5月20日 下午3:14:54
 */
@Controller
@RequestMapping(value = "syspage/menu")
public class PageMenuController extends BaseController<SysMenu, SysMenuService> {
    private String prefix = "system/menu";

    @GetMapping("/view")
    public String view()
    {
        return prefix + "/menu";
    }

    @ApiOperation(value = "查询菜单")
    @GetMapping(value = "/list")
    @RequiresPermissions("model.base.menu.read")
    @ResponseBody
    public Object query(ModelMap modelMap, @RequestParam Map<String, Object> param) {
//        Map<String, Object> param = new HashMap<>();
        return super.queryList(modelMap, param);
    }

    /**
     * 选择菜单图标
     */
    @GetMapping("/icon")
    public String icon()
    {
        return prefix + "/icon";
    }

    /**
     * 新增
     */
    @GetMapping("/add/{parentId}")
    public String add(@PathVariable("parentId") Long parentId, ModelMap mmap)
    {
        SysMenu menu = null;
        if (0L != parentId)
        {
            menu = service.queryById(parentId);
        }
        else
        {
            menu = new SysMenu();
            menu.setId(0L);
            menu.setMenuName("主目录");
        }
        mmap.put("menu", menu);
        return prefix + "/add";
    }

    /**
     * 修改菜单
     */
    @GetMapping("/edit/{menuId}")
    public String edit(@PathVariable("menuId") Long menuId, ModelMap mmap)
    {
        mmap.put("menu", service.queryById(menuId));
        return prefix + "/edit";
    }

}
